package com.share.lottery.activity.caiborecommond;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.share.lottery.R;
import com.share.lottery.adapter.PlAdapter;
import com.share.lottery.base.BaseActivity;
import com.share.lottery.base.Constants;
import com.share.lottery.model.CaiboRmdBean;
import com.share.lottery.model.CaiboRmdPlanBean;
import com.share.lottery.view.NonScrollListView;

/**
 * @author py
 *方案内容
 */
public class PlanContentActivity extends BaseActivity {
	private TextView tvFabh;
	private TextView tvFqsj;
	private TextView tvFqqh;
	private TextView tvTgz;
	private TextView tvYjqs;
	private TextView tvFanr;
	private TextView tvFasm;
	//	底部按钮
	private TextView tvBt;//倍投
	private TextView tvPl;//评论
	private TextView tvShare;//分享
	private TextView tvZan;//赞
	private TextView tvCou;//臭
	private PlAdapter adapter;
	private NonScrollListView listPl;
	private CaiboRmdBean myBean;
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.plan_content);
		init();
	}

	public void findView() {
		tvFabh = (TextView) findViewById(R.id.tv_fabh);
		tvFqsj = (TextView) findViewById(R.id.tv_fqsj);
		tvFqqh = (TextView) findViewById(R.id.tv_fqqh);
		tvTgz = (TextView) findViewById(R.id.tv_tgz);
		tvYjqs = (TextView) findViewById(R.id.tv_yjqs);
		tvFanr = (TextView) findViewById(R.id.tv_fanr);
		tvFasm = (TextView) findViewById(R.id.tv_fasm);

		tvBt = (TextView) findViewById(R.id.tv_bt);
		tvPl = (TextView) findViewById(R.id.tv_pl);
		tvShare = (TextView) findViewById(R.id.tv_share);
		tvZan = (TextView) findViewById(R.id.tv_zan);
		tvCou = (TextView) findViewById(R.id.tv_chou);
		

	}

	private void doMessage(Message msg,int tag) {
		if (tag == 0) {
			
		
		switch (msg.arg1) {
		case Constants.HTTP_OK://请求成功
			CaiboRmdPlanBean bean = (CaiboRmdPlanBean) msg.obj;
			if (bean != null) {
				setContent(bean);
			}


			break;
		case Constants.HTTP_ERROR://请求错误
			String serror = (String) msg.obj;
			showShortToast(serror);
			break;
		case Constants.HTTP_ERROR_PASER://数据解析错误
			showShortToast("数据解析错误");
			break;
		case Constants.HTTP_ERROR_NET://网络错误

			showShortToast("网络错误，请检查网络");
			break;

		default:
			break;
		}
		}else if (tag == 1) {
			
			switch (msg.arg1) {
			case Constants.HTTP_OK://请求成功
				List<CaiboRmdPlanBean>  beans = (List<CaiboRmdPlanBean>) msg.obj;
				if (beans != null) {
					adapter.addDatas(beans);
				}else {
					showShortToast("暂无评论数据");
				}


				break;
			case Constants.HTTP_ERROR://请求错误
				String serror = (String) msg.obj;
				showShortToast(serror);
				break;
			case Constants.HTTP_ERROR_PASER://数据解析错误
				showShortToast("数据解析错误");
				break;
			case Constants.HTTP_ERROR_NET://网络错误

				showShortToast("网络错误，请检查网络");
				break;

			default:
				break;
			}
			
			
		}

	}

	private void setContent(CaiboRmdPlanBean bean) {

		tvFabh.setText(bean.getPlanNo());
		tvFqsj.setText(bean.getPublishTime());
		tvFqqh.setText(bean.getIssue());
		tvTgz.setText(bean.getUserName());
		tvYjqs.setText(bean.getPreIssue()+"期");
		tvFanr.setText(bean.getContent());
		tvFasm.setText(bean.getDescription());

	}

	Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case Constants.CAIBO_RMD_PLAN:
				doMessage(msg,0);
				break;
			case Constants.CAIBO_RMD_COMMENT_GET://评论内容
				dismissProgressDialog();
				doMessage(msg,1);
				break;
				

			default:
				break;
			}

		}


	};
	public void getData() {
		listPl  = (NonScrollListView) findViewById(R.id.list_pl);
		if (adapter == null) {
			adapter = new PlAdapter(this);
		}
		listPl.setAdapter(adapter);
		Bundle bundle = getIntent().getExtras();
		String planId = "";
		if (bundle != null) {
			CaiboRmdBean bean = (CaiboRmdBean) bundle.get("cbbean");
			myBean = bean;
			planId = bean.getPlanId();
		}
		showProgreessDialog();
//		CaiboRmdController.getInstance().caibaoRmdPlan(handler, planId);
//		CaiboRmdController.getInstance().caibaoRmdComment_get(handler, planId, 0);
	}

	private TextView titleTv;
	
	public void initTitle() {
		ImageButton titleLeftImg = (ImageButton) findViewById(R.id.title_left_img);
		ImageButton titleRightImg = (ImageButton) findViewById(R.id.title_right_img);
		titleTv = (TextView) findViewById(R.id.title_tv_center);

		titleLeftImg.setImageResource(R.drawable.back);
		titleTv.setText("方案内容");
		titleRightImg.setVisibility(View.VISIBLE);


	}


	public void setData() {
		
	}

	public void setonCliker() {
		tvBt.setOnClickListener(this);
		tvPl.setOnClickListener(this);
		tvShare.setOnClickListener(this);
		tvZan.setOnClickListener(this);
		tvCou.setOnClickListener(this);

	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_bt://倍投

			break;
		case R.id.tv_pl://评论
			
			Intent intent = new Intent();
			intent.setClass(getApplicationContext(), WritePlActivity.class);
			intent.putExtra("cbbean", myBean);
			startActivity(intent);
			break;
		case R.id.tv_share://分享

			break;
		case R.id.tv_zan://赞

			break;
		case R.id.tv_chou://臭s

			break;

		default:
			break;
		}
	}

}
